/**
 *
 */
package com.saber.analyzerException;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;


/**
 * 异常分析适配器
 *
 * @author Administrator
 *
 */
public class AnalyzerExceptionAdapter extends AnalyzerException {

	private final Logger logger = LoggerFactory.getLogger(AnalyzerExceptionAdapter.class);

	/**
	 * 异常分析类型Map
	 */
	private static Map<String, AnalyzerException> eaMap = new HashMap<String, AnalyzerException>();

	static {
		eaMap.put(ExceptionType.USER_EXCEPTION, new UserException());
		eaMap.put(ExceptionType.HOST_EXCEPTION, new HostException());
	}

	/**
	 * @param json
	 * @param type
	 */
	public void analyzerException(JSONObject json, String type) {
		// 根据Type获取对应的异常分析实例
		AnalyzerException ae = eaMap.get(type);
		if (ae == null) {
			//System.out.println("Invalid Exception Type. No AnalyzerException Can Be Created");
			logger.error("Invalid Exception Type. No AnalyzerException Can Be Created");
			return;
		}
		// 分析数据源
		ae.analyzerJson(json);
		// 判断并存储异常
		ae.createException();
		// 后续操作
		ae.afterExecute();
	}
}
